package org.tron.core;

import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.tron.core.zen.ZksnarkInitService.librustzcashInitZksnarkParams;

import java.math.BigInteger;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Test;
import org.tron.api.GrpcAPI.PrivateParameters;
import org.tron.api.GrpcAPI.PrivateParametersWithoutAsk;
import org.tron.api.GrpcAPI.PrivateShieldedTRC20Parameters;
import org.tron.api.GrpcAPI.PrivateShieldedTRC20ParametersWithoutAsk;
import org.tron.api.GrpcAPI.ShieldedAddressInfo;
import org.tron.api.GrpcAPI.ShieldedTRC20Parameters;
import org.tron.common.BaseTest;
import org.tron.common.utils.ByteArray;
import org.tron.core.capsule.TransactionCapsule;
import org.tron.core.config.args.Args;
import org.tron.core.exception.ContractExeException;
import org.tron.core.exception.ContractValidateException;
import org.tron.core.services.http.JsonFormat;
import org.tron.core.services.http.JsonFormat.ParseException;


public class ShieldWalletTest extends BaseTest {

  @Resource
  private Wallet wallet;

  static {
    Args.setParam(new String[] {"-d", dbPath()}, Constant.TEST_CONF);
  }

  @Test
  public void testCreateShieldedTransaction1() {
    librustzcashInitZksnarkParams();
    String transactionStr1 = new String(ByteArray.fromHexString(
        "0x7b0a20202020227472616e73706172656e745f66726f6d5f61646472657373223a202234433930413"
            + "73241433344414546324536383932343545463430303839443634314345414337373433323433414233"
            + "31333136303030222c0a202020202266726f6d5f616d6f756e74223a203130303030303030302c0a202"
            + "02020226f766b223a223566643165636466643637396232616461333337623235306231303234373138"
            + "6633316439636237316361653664666363396131613637626134373033643863222c0a2020202022736"
            + "869656c6465645f7265636569766573223a205b0a20202020202020207b0a2020202020202020202020"
            + "20226e6f7465223a207b0a202020202020202020202020202020202276616c7565223a2039303030303"
            + "030302c0a20202020202020202020202020202020227061796d656e745f61646472657373223a20227a"
            + "74726f6e3179616d336a723270746d79706c707030747978387974707a36736a64786364657a306a333"
            + "36673636d656a76376e6863346171336d766b687275726772777671653932636a6c68356b3367222c0a"
            + "202020202020202020202020202020202272636d223a202237323330353362636266656364663564613"
            + "63663313861623033373634373665663330386336316237616265383931623263303165393033626362"
            + "3837633065222c0a20202020202020202020202020202020226d656d6f223a20223232323232220a202"
            + "0202020202020202020207d0a20202020202020207d0a202020205d0a7d"));
    PrivateParameters.Builder builder1 = PrivateParameters.newBuilder();
    try {
      JsonFormat.merge(transactionStr1, builder1, false);
    } catch (ParseException e) {
      Assert.fail();
    }

    try {
      TransactionCapsule transactionCapsule = wallet.createShieldedTransaction(builder1.build());
      Assert.assertNotNull(transactionCapsule);
    } catch (Exception e) {
      Assert.fail();
    }
  }

  @Test
  public void testCreateShieldedTransaction2() {
    librustzcashInitZksnarkParams();
    String transactionStr2 = new String(ByteArray.fromHexString(
        "7b0a202020202261736b223a20223938666430333136376632333437623534643737323338343137663"
            + "6373038643537323939643938376362613838353564653037626532346236316464653064222c0a2020"
            + "2020226e736b223a2022643063623330653764306634653435333535363134333463303462616339316"
            + "63039643230653664366234363361623031626534663531386230363839653039222c0a20202020226f"
            + "766b223a202235666431656364666436373962326164613333376232353062313032343731386633316"
            + "439636237316361653664666363396131613637626134373033643863222c0a2020202022736869656c"
            + "6465645f7370656e6473223a205b0a20202020202020207b200a090909226e6f7465223a207b0a20202"
            + "0202020202020202020202020202276616c7565223a2039303030303030302c0a202020202020202020"
            + "20202020202020227061796d656e745f61646472657373223a20227a74726f6e3179616d336a7232707"
            + "46d79706c707030747978387974707a36736a64786364657a306a33336673636d656a76376e68633461"
            + "71336d766b687275726772777671653932636a6c68356b3367222c0a202020202020202020202020202"
            + "020202272636d223a202237323330353362636266656364663564613636633138616230333736343736"
            + "656633303863363162376162653839316232633031653930336263623837633065222c0a20202020202"
            + "020202020202020202020226d656d6f223a20223232323232220a2020202020202020202020207d2c0a"
            + "20202020202020202020202022616c706861223a2022323936656531633532633933663734306433616"
            + "23162373265366463663561626231643666343965643865646236663334656633666462366537366335"
            + "353063222c0a20202020202020202020202022766f7563686572223a207b0a202020202020202020202"
            + "0202274726565223a207b0a20202020202020202020202020202020226c656674223a207b0a20202020"
            + "2020202020202020202020202020202022636f6e74656e74223a2022346565653236313963343862613"
            + "26264303235303235363330636430313362616361663337653961323162323965333938393735623763"
            + "653864363436613265220a202020202020202020202020202020207d2c0a20202020202020202020202"
            + "020202020227269676874223a207b0a202020202020202020202020202020202020202022636f6e7465"
            + "6e74223a202235333863326139313537313333356334666138383866396234336239666164643931633"
            + "334666366326265666130333931353932613564366535343539623537220a2020202020202020202020"
            + "20202020207d0a2020202020202020202020207d2c0a202020202020202020202020227274223a20226"
            + "33539376436633235663131623938613638303034343838393138386638613934616237393265353432"
            + "32313461386636346632363334616535346535353531220a20202020202020207d2c0a2020202020202"
            + "020202020202270617468223a2022323032306232656564303331643464366134663032613039376638"
            + "30623534636331353431643431363363366236663539373166383862366534316433356335333831343"
            + "23031323933356631346236373635303962383165623439656632356633393236396564373233303932"
            + "33386234633134353830333534346236343664636136326432306531663334623033346434613363643"
            + "23835353765323930376562663939306339313866363465636235306139346630316436666461356361"
            + "35633765663732323032386537623834316463626334376363656236396437636238643934323435666"
            + "23763623262613361376136626331386631336639343566376462643665326132306135313232633038"
            + "66663963313631643963613666633436323037333339366337643764333865386565343863646233626"
            + "56137653232333031333465643661323064326531363432633961343632323239323839653562306533"
            + "62376639303038653033303163626239333338356565306532316461323534353037336362353832303"
            + "13664363235323936383937316138336461383532316436353338326536316630313736363436643737"
            + "31633931353238653332373665653435333833653461323066656530653532383032636230633436623"
            + "16562346433373663363236393766343735396636633839313766613335323537313230326664373738"
            + "66643731323230346336393337643738663432363835663834623433616433623762303066383132383"
            + "53636326638356336613638656631316436326164316133656530383530323030373639353537626336"
            + "38326231626633303836343666643062323265363438653862396539386635376532396635616634306"
            + "63665646238333365326334393230303865656162306331336162643630363965363331303139376266"
            + "38306639633165613664653738666431396362616532346434613532306536636633303233323038643"
            + "56661343365356131306431313630356163373433306261316635643831666231623638643239613634"
            + "30343035373637373439653834313532373637333230366163613834343864383236336535343764356"
            + "66632393530653265643338333965393938643331636263366163396664353762633630303262313539"
            + "32313632306364316338646266366533616363376138303433396263343936326366323562396463653"
            + "76338393666336135626437303830336663356130653333636630303230366564623136643031393037"
            + "62373539393737643736353064616437653365633034396166316133643837353338306236393763383"
            + "63263396563356435316332303165613636373566393535316565623964666161613932343762633938"
            + "35383237306433643361346335616661373137376139383464356564316265323435313230643661636"
            + "46564663935663630386530396661353366623433646364303939303437353732366335313331323130"
            + "63396535636165616239376630653634326632306264373462323561616362393233373861383731626"
            + "63237643232356366633236626163613334346131656133356664643934353130663364313537303832"
            + "63323031623737646163346432346662373235386333633532383730346335393433306236333037313"
            + "86265633438363432313833373032316366373564616236353132306563363737313134633237323036"
            + "66356465626331633165643636663935653262313838356461356237626533643733366231646539383"
            + "53739343733303438323034373737633837373661336231653639623733613632666137303166613466"
            + "37613632383264396165653263376136623832653739333764373038316332336332306261343962363"
            + "53966626430623733333432313165613661396439646631383563373537653730616138316461353632"
            + "66623931326238346634396263653732323034336666353435376631336239323662363164663535326"
            + "43465343032656536646331343633663939613533356639613731333433393236346435623631366232"
            + "30376239396162646333373330393931636339323734373237643764383264323863623739346564626"
            + "33730333462346630303533666637633462363830343434323064366336333961633234623436626431"
            + "39333431633931623133666463616233313538316464616637663134313133333661323731663364306"
            + "16135323831333230386163396366396333393165336664343238393164323732333861383161386135"
            + "63316433613732623162636265613863663434613538636537333839363133323039313264383262326"
            + "33262636132333166373165666366363137333766626630613038626566613034313632313561656566"
            + "35336538626236643233333930613230653131306465363563393037623964656134616530626438336"
            + "13462306135316265613137353634366136346331326234633966393331623263623331623439323064"
            + "38323833333836656632656630376562646262343338336331326137333961393533613464366530643"
            + "66662313133396134303336643639336266626236633230666665396663303366313862313736633939"
            + "38383036343339666630626238616431393361666462323762326363626338383835363931366464383"
            + "03465333432303831376465333661623264353766656230373736333462636137373831396338653062"
            + "64323938633034663666656430653661383363633133353663613135353230346565653236313963343"
            + "86261326264303235303235363330636430313362616361663337653961323162323965333938393735"
            + "62376365386436343661326530313030303030303030303030303030220a20202020202020207d0a202"
            + "020205d2c0a2020202022736869656c6465645f7265636569766573223a205b0a20202020202020207b"
            + "0a202020202020202020202020226e6f7465223a207b0a2020202020202020202020202020202022766"
            + "16c7565223a2038303030303030302c0a20202020202020202020202020202020227061796d656e745f"
            + "61646472657373223a20227a74726f6e31356b657a70736d71303568336d616a6e6c7a6834306772796"
            + "a6d676d3630783265686a7967633771387336376d6c753835376375747177613334386e76706765706e"
            + "35786b336735727278222c0a202020202020202020202020202020202272636d223a202237323330353"
            + "36263626665636466356461363663313861623033373634373665663330386336316237616265383931"
            + "6232633031653930336263623837633065222c0a20202020202020202020202020202020226d656d6f2"
            + "23a2022313131313131313131220a2020202020202020202020207d0a20202020202020207d0a202020"
            + "205d2c0a202020202276697369626c6522203a20747275650a7d"));
    PrivateParameters.Builder builder2 = PrivateParameters.newBuilder();
    try {
      JsonFormat.merge(transactionStr2, builder2, true);
    } catch (ParseException e) {
      Assert.fail();
    }

    try {
      TransactionCapsule transactionCapsule = wallet.createShieldedTransaction(builder2.build());
      Assert.assertNotNull(transactionCapsule);
    } catch (Exception e) {
      Assert.fail();
    }
  }

  @Test
  public void testCreateShieldedTransactionWithoutSpendAuthSig() {
    librustzcashInitZksnarkParams();
    String transactionStr3 = new String(ByteArray.fromHexString(
        "7b0a2020202022616b223a2022373161643638633466353035373464356164333735343863626538363"
            + "63031663732393662393161306362303535353733313462373830383437323730326465222c0a202020"
            + "20226e736b223a202264306362333065376430663465343533353536313433346330346261633931663"
            + "039643230653664366234363361623031626534663531386230363839653039222c0a20202020226f76"
            + "6b223a20223566643165636466643637396232616461333337623235306231303234373138663331643"
            + "9636237316361653664666363396131613637626134373033643863222c0a2020202022736869656c64"
            + "65645f7370656e6473223a205b0a20202020202020207b0a202020202020202020202020226e6f74652"
            + "23a207b0a202020202020202020202020202020202276616c7565223a2039303030303030302c0a2020"
            + "2020202020202020202020202020227061796d656e745f61646472657373223a20227a74726f6e31796"
            + "16d336a723270746d79706c707030747978387974707a36736a64786364657a306a33336673636d656a"
            + "76376e6863346171336d766b687275726772777671653932636a6c68356b3367222c0a2020202020202"
            + "02020202020202020202272636d223a2022373233303533626362666563646635646136366331386162"
            + "30333736343736656633303863363162376162653839316232633031653930336263623837633065222"
            + "c0a20202020202020202020202020202020226d656d6f223a20223232323232220a2020202020202020"
            + "202020207d2c0a20202020202020202020202022616c706861223a20223239366565316335326339336"
            + "63734306433616231623732653664636635616262316436663439656438656462366633346566336664"
            + "62366537366335353063222c0a20202020202020202020202022766f7563686572223a207b0a2020202"
            + "02020202020202020202020202274726565223a207b0a20202020202020202020202020202020202020"
            + "20226c656674223a207b0a20202020202020202020202020202020202020202020202022636f6e74656"
            + "e74223a2022346565653236313963343862613262643032353032353633306364303133626163616633"
            + "37653961323162323965333938393735623763653864363436613265220a20202020202020202020202"
            + "020202020202020207d2c0a2020202020202020202020202020202020202020227269676874223a207b"
            + "0a20202020202020202020202020202020202020202020202022636f6e74656e74223a2022353338633"
            + "26139313537313333356334666138383866396234336239666164643931633334666366326265666130"
            + "333931353932613564366535343539623537220a20202020202020202020202020202020202020207d0"
            + "a202020202020202020202020202020207d2c0a20202020202020202020202020202020227274223a20"
            + "22633539376436633235663131623938613638303034343838393138386638613934616237393265353"
            + "43232313461386636346632363334616535346535353531220a2020202020202020202020207d2c0a20"
            + "20202020202020202020202270617468223a20223230323062326565643033316434643661346630326"
            + "13039376638306235346363313534316434313633633662366635393731663838623665343164333563"
            + "35333831343230313239333566313462363736353039623831656234396566323566333932363965643"
            + "73233303932333862346331343538303335343462363436646361363264323065316633346230333464"
            + "34613363643238353537653239303765626639393063393138663634656362353061393466303164366"
            + "66461356361356337656637323230323865376238343164636263343763636562363964376362386439"
            + "34323435666237636232626133613761366263313866313366393435663764626436653261323061353"
            + "13232633038666639633136316439636136666334363230373333393663376437643338653865653438"
            + "63646233626561376532323330313334656436613230643265313634326339613436323232393238396"
            + "53562306533623766393030386530333031636262393333383565653065323164613235343530373363"
            + "62353832303136643632353239363839373161383364613835323164363533383265363166303137363"
            + "63436643737316339313532386533323736656534353338336534613230666565306535323830326362"
            + "30633436623165623464333736633632363937663437353966366338393137666133353235373132303"
            + "26664373738666437313232303463363933376437386634323638356638346234336164336237623030"
            + "66383132383536363266383563366136386566313164363261643161336565303835303230303736393"
            + "53537626336383262316266333038363436666430623232653634386538623965393866353765323966"
            + "35616634306636656462383333653263343932303038656561623063313361626436303639653633313"
            + "03139376266383066396331656136646537386664313963626165323464346135323065366366333032"
            + "33323038643566613433653561313064313136303561633734333062613166356438316662316236386"
            + "43239613634303430353736373734396538343135323736373332303661636138343438643832363365"
            + "35343764356666323935306532656433383339653939386433316362633661633966643537626336303"
            + "03262313539323136323063643163386462663665336163633761383034333962633439363263663235"
            + "62396463653763383936663361356264373038303366633561306533336366303032303665646231366"
            + "43031393037623735393937376437363530646164376533656330343961663161336438373533383062"
            + "36393763383632633965633564353163323031656136363735663935353165656239646661616139323"
            + "43762633938353832373064336433613463356166613731373761393834643565643162653234353132"
            + "30643661636465646639356636303865303966613533666234336463643039393034373537323663353"
            + "13331323130633965356361656162393766306536343266323062643734623235616163623932333738"
            + "61383731626632376432323563666332366261636133343461316561333566646439343531306633643"
            + "13537303832633230316237376461633464323466623732353863336335323837303463353934333062"
            + "36333037313862656334383634323138333730323163663735646162363531323065633637373131346"
            + "33237323036663564656263316331656436366639356532623138383564613562376265336437333662"
            + "31646539383537393437333034383230343737376338373736613362316536396237336136326661373"
            + "03166613466376136323832643961656532633761366238326537393337643730383163323363323062"
            + "61343962363539666264306237333334323131656136613964396466313835633735376537306161383"
            + "16461353632666239313262383466343962636537323230343366663534353766313362393236623631"
            + "64663535326434653430326565366463313436336639396135333566396137313334333932363464356"
            + "23631366232303762393961626463333733303939316363393237343732376437643832643238636237"
            + "39346564626337303334623466303035336666376334623638303434343230643663363339616332346"
            + "23436626431393334316339316231336664636162333135383164646166376631343131333336613237"
            + "31663364306161353238313332303861633963663963333931653366643432383931643237323338613"
            + "83161386135633164336137326231626362656138636634346135386365373338393631333230393132"
            + "64383262326332626361323331663731656663663631373337666266306130386265666130343136323"
            + "13561656566353365386262366432333339306132306531313064653635633930376239646561346165"
            + "30626438336134623061353162656131373536343661363463313262346339663933316232636233316"
            + "23439323064383238333338366566326566303765626462623433383363313261373339613935336134"
            + "64366530643666623131333961343033366436393362666262366332306666653966633033663138623"
            + "13736633939383830363433396666306262386164313933616664623237623263636263383838353639"
            + "31366464383034653334323038313764653336616232643537666562303737363334626361373738313"
            + "96338653062643239386330346636666564306536613833636331333536636131353532303465656532"
            + "36313963343862613262643032353032353633306364303133626163616633376539613231623239653"
            + "3393839373562376365386436343661326530313030303030303030303030303030220a202020202020"
            + "20207d0a202020205d2c0a2020202022736869656c6465645f7265636569766573223a205b0a2020202"
            + "0202020207b0a202020202020202020202020226e6f7465223a207b0a20202020202020202020202020"
            + "2020202276616c7565223a2038303030303030302c0a202020202020202020202020202020202270617"
            + "96d656e745f61646472657373223a20227a74726f6e31356b657a70736d71303568336d616a6e6c7a68"
            + "34306772796a6d676d3630783265686a7967633771387336376d6c753835376375747177613334386e7"
            + "6706765706e35786b336735727278222c0a202020202020202020202020202020202272636d223a2022"
            + "37323330353362636266656364663564613636633138616230333736343736656633303863363162376"
            + "162653839316232633031653930336263623837633065222c0a20202020202020202020202020202020"
            + "226d656d6f223a2022313131313131313131220a2020202020202020202020207d0a202020202020202"
            + "07d0a202020205d2c0a202020202276697369626c65223a20747275650a7d"));
    PrivateParametersWithoutAsk.Builder builder3 = PrivateParametersWithoutAsk.newBuilder();
    try {
      JsonFormat.merge(transactionStr3, builder3, false);
    } catch (ParseException e) {
      Assert.fail();
    }

    try {
      TransactionCapsule transactionCapsule = wallet.createShieldedTransactionWithoutSpendAuthSig(
          builder3.build());
      Assert.assertNotNull(transactionCapsule);
    } catch (Exception e) {
      Assert.fail();
    }
  }

  @Test
  public void testGetNewShieldedAddress() {
    librustzcashInitZksnarkParams();
    try {
      ShieldedAddressInfo shieldedAddressInfo = wallet.getNewShieldedAddress();
      Assert.assertNotNull(shieldedAddressInfo);
    } catch (Exception e) {
      Assert.fail();
    }
  }

  @Test
  public void testCreateShieldedContractParameters() throws ContractExeException {
    librustzcashInitZksnarkParams();
    Args.getInstance().setFullNodeAllowShieldedTransactionArgs(true);
    Wallet wallet1 = spy(new Wallet());

    doReturn(BigInteger.valueOf(1).toByteArray())
        .when(wallet1).getShieldedContractScalingFactor(
            ByteArray.fromHexString("4144007979359ECAC395BBD3CEF8060D3DF2DC3F01"));
    String parameter = new String(ByteArray.fromHexString(
        "7b0a202020202261736b223a22633235313365396533303834393439333262643832653063653533363"
            + "63264313734323164393062373261383437316130613132623835353261333336653032222c0a202020"
            + "20226e736b223a223463366266336464346130363433643230623632386637653435393830633565313"
            + "8376630376135316436663365383661616631616239313663303765623064222c0a20202020226f766b"
            + "223a2231376135386439613530353864613665343263613132636432383964306136616131363962393"
            + "236633138653139626361353138623864366638363734653433222c0a202020202266726f6d5f616d6f"
            + "756e74223a22313030222c0a2020202022736869656c6465645f7265636569766573223a5b0a2020202"
            + "0202020207b0a202020202020202020202020226e6f7465223a7b0a2020202020202020202020202020"
            + "20202276616c7565223a3130302c0a20202020202020202020202020202020227061796d656e745f616"
            + "46472657373223a227a74726f6e317939397536656a71656e757076666b70356736713679716b703061"
            + "34346334386374613064643567656a7471613476323768716132636768667664786e6d6e65683671717"
            + "1303366613735222c0a202020202020202020202020202020202272636d223a22313662366635653430"
            + "34343461623765656162313161653636313363323766333531313739373165666138376237313536306"
            + "235383133383239633933393064220a2020202020202020202020207d0a20202020202020207d0a2020"
            + "20205d2c0a2020202022736869656c6465645f54524332305f636f6e74726163745f616464726573732"
            + "23a22343134343030373937393335394543414333393542424433434546383036304433444632444333"
            + "463031220a7d"));
    PrivateShieldedTRC20Parameters.Builder builder = PrivateShieldedTRC20Parameters.newBuilder();
    try {
      JsonFormat.merge(parameter, builder, false);
    } catch (ParseException e) {
      Assert.fail();
    }

    try {
      ShieldedTRC20Parameters shieldedTRC20Parameters = wallet1.createShieldedContractParameters(
          builder.build());
      Assert.assertNotNull(shieldedTRC20Parameters);
    } catch (Exception e) {
      Assert.fail();
    }
  }

  @Test
  public void testCreateShieldedContractParameters2() throws ContractExeException {
    librustzcashInitZksnarkParams();
    Args.getInstance().setFullNodeAllowShieldedTransactionArgs(true);
    Wallet wallet1 = spy(new Wallet());

    doReturn(BigInteger.valueOf(1).toByteArray())
        .when(wallet1).getShieldedContractScalingFactor(
            ByteArray.fromHexString("4144007979359ECAC395BBD3CEF8060D3DF2DC3F01"));
    String parameter = new String(ByteArray.fromHexString(
        "7b0a202020202261736b223a2263323531336539653330383439343933326264383265306365353336"
            + "363264313734323164393062373261383437316130613132623835353261333336653032222c0a202"
            + "02020226e736b223a2234633662663364643461303634336432306236323866376534353938306335"
            + "653138376630376135316436663365383661616631616239313663303765623064222c0a202020202"
            + "26f766b223a2231376135386439613530353864613665343263613132636432383964306136616131"
            + "363962393236633138653139626361353138623864366638363734653433222c0a202020202266726"
            + "f6d5f616d6f756e74223a22313030222c0a2020202022736869656c6465645f726563656976657322"
            + "3a5b0a20202020202020207b0a202020202020202020202020226e6f7465223a7b0a2020202020202"
            + "02020202020202020202276616c7565223a3130302c0a202020202020202020202020202020202270"
            + "61796d656e745f61646472657373223a22222c0a202020202020202020202020202020202272636d2"
            + "23a223136623666356534303434346162376565616231316165363631336332376633353131373937"
            + "3165666138376237313536306235383133383239633933393064220a2020202020202020202020207"
            + "d0a20202020202020207d0a202020205d2c0a2020202022736869656c6465645f54524332305f636f"
            + "6e74726163745f61646472657373223a2234313434303037393739333539454341433339354242443"
            + "3434546383036304433444632444333463031220a7d"));

    PrivateShieldedTRC20Parameters.Builder builder = PrivateShieldedTRC20Parameters.newBuilder();
    try {
      JsonFormat.merge(parameter, builder, false);
    } catch (ParseException e) {
      Assert.fail();
    }

    try {
      wallet1.createShieldedContractParameters(builder.build());
      Assert.fail();
    } catch (Exception e) {
      Assert.assertTrue(e instanceof ContractValidateException);
      Assert.assertEquals("PaymentAddress in ReceiveNote should not be empty",
          e.getMessage());
    }

    String parameter2 = new String(ByteArray.fromHexString(
        "7b0a202020202261736b223a2263323531336539653330383439343933326264383265306365353336"
            + "363264313734323164393062373261383437316130613132623835353261333336653032222c0a202"
            + "02020226e736b223a2234633662663364643461303634336432306236323866376534353938306335"
            + "653138376630376135316436663365383661616631616239313663303765623064222c0a202020202"
            + "26f766b223a2231376135386439613530353864613665343263613132636432383964306136616131"
            + "363962393236633138653139626361353138623864366638363734653433222c0a202020202266726"
            + "f6d5f616d6f756e74223a22313030222c0a2020202022736869656c6465645f7370656e6473223a5b"
            + "0a20202020202020207b0a202020202020202020202020226e6f7465223a7b0a20202020202020202"
            + "0202020202020202276616c7565223a3130302c0a2020202020202020202020202020202022706179"
            + "6d656e745f61646472657373223a22222c0a202020202020202020202020202020202272636d223a2"
            + "231366236663565343034343461623765656162313161653636313363323766333531313739373165"
            + "666138376237313536306235383133383239633933393064220a2020202020202020202020207d0a2"
            + "0202020202020207d0a202020205d2c0a2020202022736869656c6465645f54524332305f636f6e74"
            + "726163745f61646472657373223a22343134343030373937393335394543414333393542424433434"
            + "546383036304433444632444333463031220a7d"));

    builder = PrivateShieldedTRC20Parameters.newBuilder();
    try {
      JsonFormat.merge(parameter2, builder, false);
    } catch (ParseException e) {
      Assert.fail();
    }

    try {
      wallet1.createShieldedContractParameters(builder.build());
      Assert.fail();
    } catch (Exception e) {
      Assert.assertTrue(e instanceof ContractValidateException);
      Assert.assertEquals("PaymentAddress in SpendNote should not be empty",
          e.getMessage());
    }
  }

  @Test
  public void testCreateShieldedContractParametersWithoutAsk() throws ContractExeException {
    librustzcashInitZksnarkParams();
    Args.getInstance().setFullNodeAllowShieldedTransactionArgs(true);

    Wallet wallet1 = spy(new Wallet());
    doReturn(BigInteger.valueOf(1).toByteArray())
        .when(wallet1).getShieldedContractScalingFactor(
            ByteArray.fromHexString("4144007979359ECAC395BBD3CEF8060D3DF2DC3F01"));
    String parameter = new String(ByteArray.fromHexString(
        "7b0a2020202022616b223a2230656261373361343865323934396561356461613133626365663466646"
            + "633613561613966336232363830363763663831313233333938613833386665336363222c0a20202020"
            + "226e736b223a22346336626633646434613036343364323062363238663765343539383063356531383"
            + "76630376135316436663365383661616631616239313663303765623064222c0a20202020226f766b22"
            + "3a223137613538643961353035386461366534326361313263643238396430613661613136396239323"
            + "6633138653139626361353138623864366638363734653433222c0a202020202266726f6d5f616d6f75"
            + "6e74223a22313030222c0a2020202022736869656c6465645f7265636569766573223a5b0a202020202"
            + "02020207b0a202020202020202020202020226e6f7465223a7b0a202020202020202020202020202020"
            + "202276616c7565223a3130302c0a20202020202020202020202020202020227061796d656e745f61646"
            + "472657373223a227a74726f6e317939397536656a71656e757076666b70356736713679716b70306134"
            + "346334386374613064643567656a7471613476323768716132636768667664786e6d6e6568367171713"
            + "03366613735222c0a202020202020202020202020202020202272636d223a2231366236663565343034"
            + "34346162376565616231316165363631336332376633353131373937316566613837623731353630623"
            + "5383133383239633933393064220a2020202020202020202020207d0a20202020202020207d0a202020"
            + "205d2c0a2020202022736869656c6465645f54524332305f636f6e74726163745f61646472657373223"
            + "a2234313434303037393739333539454341433339354242443343454638303630443344463244433346"
            + "3031220a7d"));
    PrivateShieldedTRC20ParametersWithoutAsk.Builder builder =
        PrivateShieldedTRC20ParametersWithoutAsk.newBuilder();
    try {
      JsonFormat.merge(parameter, builder, false);
    } catch (ParseException e) {
      Assert.fail();
    }

    try {
      ShieldedTRC20Parameters shieldedTRC20Parameters =
          wallet1.createShieldedContractParametersWithoutAsk(builder.build());
      Assert.assertNotNull(shieldedTRC20Parameters);
    } catch (Exception e) {
      Assert.fail();
    }
  }
}
